package com.mostromas.ess.product.controller;

import com.mostromas.ess.entities.ProductSize;
import com.mostromas.ess.entities.ProductYear;
import com.mostromas.ess.product.service.IProductYearService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 商品年份表-前端控制器
 */
@Api(value = "商品年份管理接口",description = "年份管理接口，提供年份的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/year")
public class ProductYearController {

    @Autowired
    private IProductYearService productYearService;

    @PreAuthorize(("hasAuthority('year:search')"))
    @ApiOperation("查询商品年份详情接口")
    @ApiImplicitParam(name = "id",value = "年份ID",required = true)
    @GetMapping("/{id}") //请求路径：/product/size/{id}
    public Result view(@PathVariable("id") String id){
        ProductYear productYear = productYearService.getById(id);
        return Result.ok(productYear);
    }

    @PreAuthorize(("hasAuthority('year:edit')"))
    @ApiOperation("修改商品年份信息接口")
    @PutMapping //put方式调用接口：/product/size
    public Result update(@RequestBody ProductYear productYear){
        productYearService.updateById(productYear);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('year:add')"))
    @ApiOperation("新增商品年份信息接口")
    @PostMapping //post方式调用接口：/product/size
    public Result save(@RequestBody ProductYear productYear){
        productYearService.save(productYear);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('year:delete')"))
    @ApiOperation("删除商品年份信息接口")
    @ApiImplicitParam(name = "id",value = "年份ID",required = true)
    @DeleteMapping("/{id}") //delete方式调用接口：/product/size/{id}
    public Result delete(@PathVariable("id") String id){
        productYearService.removeById(id);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('year:search')"))
    @ApiOperation("获取所有的商品年份信息接口")
    @GetMapping("/list") //请求路径：/product/size/list
    public Result list(){
        return productYearService.selectAll();
    }
}
